<?php
//生成时间2023-03-30 16:32
class tuser{
    static private $id=NULL;//編號
    static public function Set_id($id){
        if(!is_numeric($id)){
            return "編號的输入必须是数字";
        }
        self::$id=addslashes($id);
        return 1;
    }
    static private $s_no=NULL;//工號
    static public function Set_s_no($s_no){
        if(strlen($s_no)<1 || strlen($s_no)>30){
            return "工號的输入字数不在指定范围1~30";
        }
        if(!preg_match("/^([A-Z]|[a-z]|\d)(\d{4,17}|(\d{4,17}[A-Z]\d{0,4}))|(^\d{18}$)|(^\d{17}(\d|X|x)$)$/",$s_no)){
            return "工號的输入格式错误";
        }
        self::$s_no=addslashes($s_no);
        return 1;
    }
    static private $s_name=NULL;//姓名
    static public function Set_s_name($s_name){
        if(strlen($s_name)<1 || strlen($s_name)>90){
            return "姓名的输入字数不在指定范围1~90";
        }
        self::$s_name=addslashes($s_name);
        return 1;
    }
    static private $s_sex=NULL;//性別
    static public function Set_s_sex($s_sex){
        if(strlen($s_sex)<1 || strlen($s_sex)>20){
            return "性別的输入字数不在指定范围1~20";
        }
        if(!in_array($s_sex,array("男","女"))){
            return "性別的输入必须是[男,女]";
        }
        self::$s_sex=addslashes($s_sex);
        return 1;
    }
    static private $s_mail=NULL;//郵箱
    static public function Set_s_mail($s_mail){
        if(strlen($s_mail)<1 || strlen($s_mail)>300){
            return "郵箱的输入字数不在指定范围1~300";
        }
        if(!preg_match("/^([a-zA-Z]|[0-9])(\w|\-)+@(mail.foxconn.com)|(foxconn.com)$/",$s_mail)){
            return "郵箱的输入格式错误";
        }
        self::$s_mail=addslashes($s_mail);
        return 1;
    }
    static private $s_tel=NULL;//分機
    static public function Set_s_tel($s_tel){
        if(strlen($s_tel)<1 || strlen($s_tel)>60){
            return "分機的输入字数不在指定范围1~60";
        }
        if(!preg_match("/(^\d{5,6}$)|(^\d{3}-\d{5,6}$)|(^\d{8,9}$)/",$s_tel)){
            return "分機的输入格式错误";
        }
        self::$s_tel=addslashes($s_tel);
        return 1;
    }
    static private $s_birth=NULL;//生日
    static public function Set_s_birth($s_birth){
        if(strlen($s_birth)<1 || strlen($s_birth)>20){
            return "生日的输入字数不在指定范围1~20";
        }
        if(!preg_match("/(^\d{4}\/([1-9]|1[1-2])\/([1-9]|[1-2][0-9]|3[0-1])$)|(^\d{4}\-(0[1-9]|1[0-2])\-(0[1-9]|[1-2][0-9]|3[0-1])$)/",$s_birth)){
            return "生日的输入格式错误";
        }
        self::$s_birth=addslashes($s_birth);
        return 1;
    }
    static public function Add($db){
        $params=array();
        $sql="insert into t_user_t(";
        $sql.=self::$id!=NULL?"id,":'';
        $sql.=self::$s_no!=NULL?"s_no,":'';
        $sql.=self::$s_name!=NULL?"s_name,":'';
        $sql.=self::$s_sex!=NULL?"s_sex,":'';
        $sql.=self::$s_mail!=NULL?"s_mail,":'';
        $sql.=self::$s_tel!=NULL?"s_tel,":'';
        $sql.=self::$s_birth!=NULL?"s_birth,":'';
        $sql=trim($sql,',');
        $sql.=") values (";
        if(self::$id!=NULL){
            $sql.="?,";
            array_push($params,self::$id);
        }
        if(self::$s_no!=NULL){
            $sql.="?,";
            array_push($params,self::$s_no);
        }
        if(self::$s_name!=NULL){
            $sql.="?,";
            array_push($params,self::$s_name);
        }
        if(self::$s_sex!=NULL){
            $sql.="?,";
            array_push($params,self::$s_sex);
        }
        if(self::$s_mail!=NULL){
            $sql.="?,";
            array_push($params,self::$s_mail);
        }
        if(self::$s_tel!=NULL){
            $sql.="?,";
            array_push($params,self::$s_tel);
        }
        if(self::$s_birth!=NULL){
            $sql.="?,";
            array_push($params,self::$s_birth);
        }
        $sql=trim($sql,',');
        $sql.=");";
        $dbh=$db->prepare($sql);
        $dbh->execute($params);
    }
    static public function Edit($db){
        $params=array();
        $sql="update t_user_t set ";
        if(self::$s_no!=NULL){
            $sql.=" s_no=?,";
            array_push($params,self::$s_no);
        }
        if(self::$s_name!=NULL){
            $sql.=" s_name=?,";
            array_push($params,self::$s_name);
        }
        if(self::$s_sex!=NULL){
            $sql.=" s_sex=?,";
            array_push($params,self::$s_sex);
        }
        if(self::$s_mail!=NULL){
            $sql.=" s_mail=?,";
            array_push($params,self::$s_mail);
        }
        if(self::$s_tel!=NULL){
            $sql.=" s_tel=?,";
            array_push($params,self::$s_tel);
        }
        if(self::$s_birth!=NULL){
            $sql.=" s_birth=?,";
            array_push($params,self::$s_birth);
        }
        $sql=trim($sql,',');
        $sql.=" where 1=1";
        if(self::$id!=NULL){
            $sql.=" and id=?";
            array_push($params,self::$id);
        }
        $dbh=$db->prepare($sql);
        $dbh->execute($params);
    }
    static public function Delete($db){
        $sql="delete from t_user_t";
        $sql.=" where 1=1";
        if(self::$id!=NULL){
            $sql.=" and id=?";
            array_push($params,self::$id);
        }
        $dbh=$db->prepare($sql);
        $dbh->execute($params);
    }
    static public function Select(){
        $sql="select * from t_user_t";
        return $sql;
    }
}
?>